/*
 Modulo de inicio para el logeo de usuario
 Creado por Carlos Pastelin Morales 
 29/12/2014
pastelini
 */
package Vistas;

import Controlador.Conexion;
import Controlador.SrvProducto;
import Controlador.SrvReportes;
import Controlador.SrvVenta;
import Controlador.Ticket;
import Modelo.INFONEGOCIO;
import Modelo.Ventas;
import java.awt.event.MouseEvent;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Date;
import javax.print.PrintException;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.sql.*;
import javax.swing.JTextField;
import java.lang.Object;
import java.util.Arrays;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.util.Calendar;
import java.util.EventObject;
import java.util.GregorianCalendar;
import javax.swing.table.TableCellEditor;
import java.awt.Component;
import java.awt.TextField;
import static java.awt.image.ImageObserver.ERROR;
import java.text.DecimalFormat;
import java.util.EventObject;
import javax.swing.AbstractCellEditor;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.table.TableColumn;

public class Interface extends javax.swing.JFrame implements Runnable{
/*Inicializamos las variables a utilizar*/
    Conexion con,query;
    ResultSet rs;
   public  int IDusuario;
    static int j=0,w=0,jj=0; 
    static String aux3;
    static float total=0;
    static String inv[]=new String[50000];
    static float invT=0;
   public static String id,cad;
   String hora,minutos,segundos,ampm;
    Calendar calendario;    
    Thread h1;
    public int num=0;
    public static int rowCount, numfac;
     DecimalFormat format = new DecimalFormat("0.00");
SrvProducto control=new SrvProducto(this);
SrvReportes reporte=new SrvReportes(this);
SrvVenta controlventa=new SrvVenta(this);
Ventas modeloventa=new Ventas();//Lo utilizo para traer el numero de la nota desde la vista
    /** Creates new form Interface */
    public Interface() {
    try {
            initComponents();
            h1 = new Thread(this);
            h1.start();
            con = new Conexion();

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }           
    }
    class SpinnerEditor extends AbstractCellEditor implements TableCellEditor {
  final JSpinner spinner = new JSpinner();

  public SpinnerEditor(String[] items) {
    spinner.setModel(new SpinnerListModel(Arrays.asList(items)));
  }
  

  public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
      int row, int column) {
    spinner.setValue(value);
    return spinner;
  }

  public boolean isCellEditable(EventObject evt) {
    if (evt instanceof MouseEvent) {
      return ((MouseEvent) evt).getClickCount() >= 1;
    }
    return true;
  }
 public void SpinnerListModelStateChanged(javax.swing.event.ChangeEvent evt) {
      JOptionPane.showMessageDialog(null,"aqui");  // TODO add your handling code here:
    }
  public Object getCellEditorValue() {
    return spinner.getValue();
  }
 
}
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        Eliminar = new javax.swing.JMenuItem();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        Productos = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel33 = new javax.swing.JLabel();
        jBIngresar = new javax.swing.JButton();
        lbHora2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTbuscar = new javax.swing.JTable();
        jTID = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTbdescripcion = new javax.swing.JTextField();
        jTbcodigobarras = new javax.swing.JTextField();
        jLabel38 = new javax.swing.JLabel();
        jBmodificar = new javax.swing.JButton();
        jLabel34 = new javax.swing.JLabel();
        jTbnombre2 = new javax.swing.JTextField();
        Venta = new javax.swing.JPanel();
        lbHora1 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jTcodigodebarras = new javax.swing.JTextField();
        jBfactura = new javax.swing.JButton();
        jBbuscaxnombre = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        Tlista = new javax.swing.JTable();
        jBimprimir = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTtotal = new javax.swing.JTextField();
        jBquitar = new javax.swing.JButton();
        jLabel46 = new javax.swing.JLabel();
        jEtiRFC = new javax.swing.JLabel();
        jRfc = new javax.swing.JLabel();
        jEtiTel = new javax.swing.JLabel();
        jNumTel = new javax.swing.JLabel();
        jDireccion = new javax.swing.JLabel();
        jNumVenta = new javax.swing.JLabel();
        jTIDVenta = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jNombreEmpresa = new javax.swing.JLabel();
        jDireccion1 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        Alertas = new javax.swing.JPanel();
        jBalertas = new javax.swing.JButton();
        jBalertas1 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        jLabel41 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        Talertas = new javax.swing.JTable();
        Reportes = new javax.swing.JPanel();
        jScrollPane9 = new javax.swing.JScrollPane();
        jTinventario = new javax.swing.JTable();
        jCuser = new javax.swing.JComboBox();
        jButton3 = new javax.swing.JButton();
        lbHora = new javax.swing.JLabel();
        jBTotalVentas = new javax.swing.JButton();
        jTinvT = new javax.swing.JTextField();
        jBVentaxDia = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jLFechafinal = new javax.swing.JLabel();
        jLFechainicial = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMusers = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();

        Eliminar.setText("Eliminar");
        Eliminar.setToolTipText("");
        Eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EliminarActionPerformed(evt);
            }
        });
        jPopupMenu1.add(Eliminar);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Administracion de recursos para micro negocios");
        setResizable(false);

        jTabbedPane1.setToolTipText("");

        Productos.setName("Productos"); // NOI18N
        Productos.setNextFocusableComponent(Venta);
        Productos.setOpaque(false);
        Productos.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                ProductosComponentShown(evt);
            }
        });
        Productos.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel4.setBackground(new java.awt.Color(204, 204, 204));
        jPanel4.setName("Productos"); // NOI18N
        jPanel4.setOpaque(false);
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel33.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel33.setText("Busqueda por codigo de barras:");
        jPanel4.add(jLabel33, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 90, -1, -1));

        jBIngresar.setText("Ingresar");
        jBIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBIngresarActionPerformed(evt);
            }
        });
        jPanel4.add(jBIngresar, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 490, 120, 40));

        lbHora2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        lbHora2.setText("jLabel42");
        jPanel4.add(lbHora2, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 50, 160, -1));

        jTbuscar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Num. Producto", "Codigo de barras", "Nombre", "Precio", "Cantidad", "Existencia", "Descripcion", "Especificacion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTbuscar.setColumnSelectionAllowed(true);
        jTbuscar.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(jTbuscar);
        jTbuscar.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        jPanel4.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, 810, 350));

        jTID.setEditable(false);
        jTID.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jPanel4.add(jTID, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 30, 70, -1));

        jLabel12.setText("ID Admin:");
        jPanel4.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 30, -1, 20));

        jTbdescripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTbdescripcionKeyReleased(evt);
            }
        });
        jPanel4.add(jTbdescripcion, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 90, 220, 20));

        jTbcodigobarras.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTbcodigobarrasKeyReleased(evt);
            }
        });
        jPanel4.add(jTbcodigobarras, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 90, 80, -1));

        jLabel38.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel38.setText("Busqueda por Nombre:");
        jPanel4.add(jLabel38, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 60, -1, -1));

        jBmodificar.setText("Modificar");
        jBmodificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBmodificarActionPerformed(evt);
            }
        });
        jPanel4.add(jBmodificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 490, 120, 40));

        jLabel34.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel34.setText("Busqueda por Descripcion:");
        jPanel4.add(jLabel34, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 90, -1, -1));

        jTbnombre2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTbnombre2KeyReleased(evt);
            }
        });
        jPanel4.add(jTbnombre2, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 60, 220, -1));

        Productos.add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 850, 550));
        jPanel4.getAccessibleContext().setAccessibleName("Productos");
        jPanel4.getAccessibleContext().setAccessibleDescription("");

        jTabbedPane1.addTab("Productos", null, Productos, "Buscar Productos y Modificarlos");
        Productos.getAccessibleContext().setAccessibleName("");

        Venta.setOpaque(false);

        lbHora1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        lbHora1.setText("jLabel42");

        jLabel32.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel32.setText("Codigo de barras:");

        jTcodigodebarras.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTcodigodebarrasKeyReleased(evt);
            }
        });

        jBfactura.setText("Factura");
        jBfactura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBfacturaActionPerformed(evt);
            }
        });

        jBbuscaxnombre.setText("Buscar por nombre");
        jBbuscaxnombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBbuscaxnombreActionPerformed(evt);
            }
        });

        Tlista.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cantidad", "Nombre", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        Tlista.setComponentPopupMenu(jPopupMenu1);
        jScrollPane5.setViewportView(Tlista);
        if (Tlista.getColumnModel().getColumnCount() > 0) {
            Tlista.getColumnModel().getColumn(0).setResizable(false);
            Tlista.getColumnModel().getColumn(1).setResizable(false);
            Tlista.getColumnModel().getColumn(2).setResizable(false);
        }

        jBimprimir.setText("Realizar Venta");
        jBimprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBimprimirActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel7.setText("Total:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 0, 0));
        jLabel8.setText("$");

        jTtotal.setEditable(false);
        jTtotal.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jTtotal.setForeground(new java.awt.Color(255, 0, 0));
        jTtotal.setText("0.00");

        jBquitar.setText("Limpiar");
        jBquitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBquitarActionPerformed(evt);
            }
        });

        jEtiRFC.setText("RFC:");

        jRfc.setText("RFC");

        jEtiTel.setText("Tel.");

        jNumTel.setText("Numero de Telefono");

        jDireccion.setText("Direccion");

        try {
            numfac = 1;
            rs = modeloventa.NumNota();
            while (rs.next()) {

                numfac++;

            }
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }
        jNumVenta.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jNumVenta.setText(Integer.toString(numfac));

        jTIDVenta.setEditable(false);
        jTIDVenta.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel13.setText("ID Admin:");

        jNombreEmpresa.setText("Nombre de la empresa");

        jDireccion1.setText("Direccion:");

        jButton4.setText("Eliminar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel1.setText("Nota #");

        jButton5.setText("Producto Comun");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout VentaLayout = new javax.swing.GroupLayout(Venta);
        Venta.setLayout(VentaLayout);
        VentaLayout.setHorizontalGroup(
            VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(VentaLayout.createSequentialGroup()
                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(VentaLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 790, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(VentaLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jBquitar, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel46, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(150, 150, 150)
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(14, 14, 14)
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, 0)
                                .addComponent(jTtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addGap(30, 30, 30)
                                .addComponent(jBfactura, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(jBimprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(VentaLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(VentaLayout.createSequentialGroup()
                                        .addComponent(jNombreEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                                        .addComponent(jDireccion1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(VentaLayout.createSequentialGroup()
                                        .addComponent(jEtiRFC)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jRfc, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(VentaLayout.createSequentialGroup()
                                        .addComponent(jEtiTel)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jNumTel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(lbHora1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(VentaLayout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jNumVenta))
                                    .addGroup(VentaLayout.createSequentialGroup()
                                        .addComponent(jLabel32)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTcodigodebarras, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jBbuscaxnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton5)))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addGap(11, 11, 11))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, VentaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel13)
                .addGap(13, 13, 13)
                .addComponent(jTIDVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        VentaLayout.setVerticalGroup(
            VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(VentaLayout.createSequentialGroup()
                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jNumVenta)
                        .addComponent(jLabel1))
                    .addComponent(jTIDVenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbHora1)
                    .addGroup(VentaLayout.createSequentialGroup()
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jDireccion)
                                .addComponent(jDireccion1))
                            .addComponent(jNombreEmpresa))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jEtiRFC)
                            .addComponent(jRfc))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jEtiTel)
                    .addComponent(jNumTel))
                .addGap(20, 20, 20)
                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel32)
                    .addComponent(jTcodigodebarras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBbuscaxnombre)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addGap(6, 6, 6)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(VentaLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addGap(70, 70, 70)
                                .addComponent(jBquitar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel46, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(VentaLayout.createSequentialGroup()
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(VentaLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jLabel7))
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(VentaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jBfactura, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jBimprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))))
        );

        jTabbedPane1.addTab("Venta", null, Venta, "Realizar una Venta");

        Alertas.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        Alertas.setOpaque(false);
        Alertas.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jBalertas.setText("Alerta Caducidad");
        jBalertas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBalertasActionPerformed(evt);
            }
        });
        Alertas.add(jBalertas, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 380, 170, 40));

        jBalertas1.setText("Alerta Existencia");
        jBalertas1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBalertas1ActionPerformed(evt);
            }
        });
        Alertas.add(jBalertas1, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 380, 180, 40));

        jLabel22.setText("Existencia menor a 10 piezas");
        Alertas.add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 420, -1, -1));

        jLabel41.setText("Caduca en Maximo 3 meses");
        Alertas.add(jLabel41, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 420, -1, -1));

        Talertas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre producto", "Caducidad", "Existencia", "Precio"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        Talertas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        Talertas.setShowVerticalLines(false);
        Talertas.getTableHeader().setReorderingAllowed(false);
        jScrollPane6.setViewportView(Talertas);

        Alertas.add(jScrollPane6, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 60, 750, 300));

        jTabbedPane1.addTab("Alertas", null, Alertas, "Alertas de Poco Producto o Caducidad");

        Reportes.setBackground(new java.awt.Color(255, 255, 255));
        Reportes.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTinventario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Num.Nota", "Producto", "Precio", "Caducidad", "Fecha", "Usuario"
            }
        ));
        jTinventario.getTableHeader().setReorderingAllowed(false);
        jScrollPane9.setViewportView(jTinventario);
        jTinventario.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        Reportes.add(jScrollPane9, new org.netbeans.lib.awtextra.AbsoluteConstraints(75, 47, 700, 314));

        jCuser.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Usuarios" }));
        Reportes.add(jCuser, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 428, 140, -1));

        jButton3.setText("Imprimir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        Reportes.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 498, 120, 40));

        lbHora.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        lbHora.setText("jLabel42");
        Reportes.add(lbHora, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 0, 160, 30));

        jBTotalVentas.setText("Total Ventas");
        jBTotalVentas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTotalVentasActionPerformed(evt);
            }
        });
        Reportes.add(jBTotalVentas, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 380, 120, 40));

        jTinvT.setEditable(false);
        jTinvT.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jTinvT.setForeground(new java.awt.Color(255, 0, 0));
        jTinvT.setText("0.00");
        Reportes.add(jTinvT, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 380, 180, 46));

        jBVentaxDia.setText("Ventas del Día");
        jBVentaxDia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBVentaxDiaActionPerformed(evt);
            }
        });
        Reportes.add(jBVentaxDia, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 458, 120, 40));

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(255, 0, 0));
        jLabel16.setText("$");
        Reportes.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 380, -1, 40));

        jDateChooser1.setDateFormatString("dd/MM/yyyy");
        jDateChooser1.setMinSelectableDate(new java.util.Date(1356998519000L));
        Reportes.add(jDateChooser1, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 390, 100, -1));

        jLabel2.setText("Por Usuario");
        Reportes.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 428, 60, -1));

        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });
        Reportes.add(jCheckBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(192, 389, 20, -1));

        jLabel3.setText("Entre");
        Reportes.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 370, 30, -1));

        jDateChooser2.setToolTipText("");
        jDateChooser2.setDateFormatString("dd/MM/yyyy");
        jDateChooser2.setEnabled(false);
        jDateChooser2.setMinSelectableDate(new java.util.Date(1356998519000L));
        Reportes.add(jDateChooser2, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 390, 100, -1));

        jLFechafinal.setText("Fecha final");
        jLFechafinal.setToolTipText("");
        Reportes.add(jLFechafinal, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 370, 100, -1));

        jLFechainicial.setText("Fecha Inicial");
        jLFechainicial.setToolTipText("");
        Reportes.add(jLFechainicial, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 370, 100, -1));

        jTabbedPane1.addTab("Reportes", null, Reportes, "Permite consultar tus ventas");

        jMenu1.setText("Agregar");

        jMusers.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMusers.setText("Usuario");
        jMusers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMusersActionPerformed(evt);
            }
        });
        jMenu1.add(jMusers);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Modificar");

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Contraseña");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        jMenu4.setText("Configuracion");

        jMenuItem3.setText("Informacion de negocion");
        jMenuItem3.setToolTipText("");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem3);

        jMenuBar1.add(jMenu4);

        jMenu5.setText("Salir");

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Cerrar Sesion");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem4);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Salir");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem5);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMusersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMusersActionPerformed
            AltaUsuario usu = new AltaUsuario();
            usu.setLocationRelativeTo(this);
            usu.setVisible(true);
}//GEN-LAST:event_jMusersActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
    modificarpass mod = new modificarpass();
    mod.id = IDusuario;
    System.out.println("id para modificar: "+mod.id);
    mod.setLocationRelativeTo(this);
    mod.setVisible(true);    
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
   AgregarInfoNegocio infonego=new AgregarInfoNegocio(this,true);
   infonego.setLocationRelativeTo(this);
   infonego.setVisible(true);
   String nomempresa="", direccion="", tel="", rfc="";
   ResultSet rs; 
   INFONEGOCIO modeloinfo = new INFONEGOCIO();
  try{
    rs = modeloinfo.Obteninfo();
            while (rs.next()) {
            nomempresa = rs.getString(1);
            direccion = rs.getString(2);
            tel = rs.getString(3);
            rfc = rs.getString(4);
    } }catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }        
   infonegocio(nomempresa, direccion, tel, rfc);
}//GEN-LAST:event_jMenuItem3ActionPerformed

    private void EliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EliminarActionPerformed
       DefaultTableModel modelo =(DefaultTableModel)Tlista.getModel(); 
       int aux = Tlista.getSelectedRow();
    if (aux==-1)
        {
            JOptionPane.showMessageDialog(null, "No se a seleccionado nada de la tabla.");
        }
    else{
       String cantidadaux=Tlista.getValueAt(aux,0).toString();
       int cantidad= Integer.parseInt(cantidadaux);
       float precio = Float.parseFloat(Tlista.getValueAt(aux, 2).toString());
       float restaprecio = cantidad * precio;
       float total =Float.parseFloat(jTtotal.getText());
       total=total-restaprecio;
       jTtotal.setText(format.format(total));
       modelo.removeRow(Tlista.getSelectedRow()); // la fila que quieres eliminar // TODO add your handling code here:
    }
    }//GEN-LAST:event_EliminarActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
     cerrar();
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
      inicio login=new inicio();
      login.setLocationRelativeTo(null);
      login.setVisible(true);
      this.dispose();
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if(jCheckBox1.isSelected()== true ){
            jDateChooser2.setEnabled(true);
        }else{
            jDateChooser2.setEnabled(false);
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jBVentaxDiaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBVentaxDiaActionPerformed
        java.util.Date date = new java.util.Date();
        java.util.Date date2 = new java.util.Date();
        date = jDateChooser1.getDate();
        date2 = jDateChooser2.getDate();
        if (date==null) {
            JOptionPane.showMessageDialog(null, "La fecha inicial no puede ir vacia");
        } else {
            if (jCheckBox1.isSelected() == true) {
                if (date2==null) {
                    JOptionPane.showMessageDialog(null, "La fecha final no puede ir vacia");
                } else {
                    if (date2.before(date)) {
                        JOptionPane.showMessageDialog(null, "La fecha final no puede ser menor a la fecha inicial");
                    } else {
                        reporte.RCriteriosVenta();
                    }
                }
            } else {
            reporte.RCriteriosVenta();
        }
        }
    }//GEN-LAST:event_jBVentaxDiaActionPerformed

    private void jBTotalVentasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTotalVentasActionPerformed
        reporte.RTotalVenta();
    }//GEN-LAST:event_jBTotalVentasActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jBalertas1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBalertas1ActionPerformed
        control.alertasexistencia();                           // TODO add your handling code here:
    }//GEN-LAST:event_jBalertas1ActionPerformed

    private void jBalertasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBalertasActionPerformed
        control.alerta();
    }//GEN-LAST:event_jBalertasActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        AgregarProductoComun ProComun=new AgregarProductoComun(this,true);
        ProComun.setLocationRelativeTo(this);
        ProComun.setVentana(this);
        ProComun.setVisible(true);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        DefaultTableModel modelo =(DefaultTableModel)Tlista.getModel();
        int aux = Tlista.getSelectedRow();
        if (aux==-1)
        {
            JOptionPane.showMessageDialog(null, "No se a seleccionado nada de la tabla.");
        }
        else{
            String cantidadaux=Tlista.getValueAt(aux,0).toString();
            int cantidad= Integer.parseInt(cantidadaux);
            float precio = Float.parseFloat(Tlista.getValueAt(aux, 2).toString());
            float restaprecio = cantidad * precio;
            float total =Float.parseFloat(jTtotal.getText());
            total=total-restaprecio;
            jTtotal.setText(format.format(total));
            modelo.removeRow(Tlista.getSelectedRow()); // la fila que quieres eliminar // TODO add your handling code here:
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jBquitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBquitarActionPerformed
        control.limpiarcarrito();
    }//GEN-LAST:event_jBquitarActionPerformed

    private void jBimprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBimprimirActionPerformed
        if (Tlista.getRowCount() == 0) {
            JOptionPane.showMessageDialog(null, "No hay ningun elemento  en la Tabla de Venta");
        } else {
            Ticket imp = new Ticket(this);
            try {
                controlventa.RealizaVenta();
                if (JOptionPane.showConfirmDialog(rootPane, "Quieres imprimir el Ticket?", "Imprimir Ticket", 1) == 0) {
                    imp.print();
                }
                total = 0;
                jTtotal.setText("0.00");
                int x = Tlista.getRowCount() - 1;
                DefaultTableModel temp = (DefaultTableModel) Tlista.getModel();
                while (x >= 0) {
                    temp.removeRow(x);
                    x--;
                }
                try {
                    numfac = 1;
                    rs = modeloventa.NumNota();
                    while (rs.next()) {
                        numfac++;
                    }
                    jNumVenta.setText(Integer.toString(numfac));
                } catch (SQLException ex) {
                    Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (IOException ex) {
                Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jBimprimirActionPerformed

    private void jBbuscaxnombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBbuscaxnombreActionPerformed
        BuscarProducto buscanombre=new BuscarProducto(this,true);
        buscanombre.setLocationRelativeTo(this);
        buscanombre.setVentana(this);
        buscanombre.setVisible(true);
    }//GEN-LAST:event_jBbuscaxnombreActionPerformed

    private void jBfacturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBfacturaActionPerformed
        control.facturaventa();
    }//GEN-LAST:event_jBfacturaActionPerformed

    private void jTcodigodebarrasKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTcodigodebarrasKeyReleased
        int evento=evt.getKeyCode();
        if(evento==10 ){
            control.AgregarVenta();  // TODO add your handling code here:
            DefaultTableModel temp = (DefaultTableModel)
            Tlista.getModel();
            TableColumn col = Tlista.getColumnModel().getColumn(0);
            String[] values = new String[100];
            for (int i = 1; i < 100; i++) {
                values[i] = new String(Integer.toString(i));
            }
            col.setCellEditor(new SpinnerEditor(values));
        }
    }//GEN-LAST:event_jTcodigodebarrasKeyReleased

    private void ProductosComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_ProductosComponentShown
        control.buscarproducto();
    }//GEN-LAST:event_ProductosComponentShown

    private void jTbnombre2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbnombre2KeyReleased
        control.buscarproducto(); // TODO add your handling code here:
    }//GEN-LAST:event_jTbnombre2KeyReleased

    private void jBmodificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBmodificarActionPerformed
        int Opcion=jTbuscar.getSelectedRow();//Obtenemos si esta seleccionado un producto de la tabla
        if(Opcion>=0){//C.P.M Preguntamos si la obcion seleccionada es mayor que 0 debido a que -1 es cuando no se a seleccionado nada
            control.modificar();//C.P.M si es asi es que esta seleccionado algun producto y entramos a modificarlo
        }
        else{
            JOptionPane.showMessageDialog(rootPane,"Selecciona un producto para modificarlo");//C.P.M de lo contrario lo modificamos
        }
    }//GEN-LAST:event_jBmodificarActionPerformed

    private void jTbcodigobarrasKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbcodigobarrasKeyReleased
        control.buscaxcodigo(); // TODO add your handling code here:
    }//GEN-LAST:event_jTbcodigobarrasKeyReleased

    private void jTbdescripcionKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTbdescripcionKeyReleased
        control.buscarxdescrip();
    }//GEN-LAST:event_jTbdescripcionKeyReleased

    private void jBIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBIngresarActionPerformed
        AltaProductos alta=new AltaProductos(this,true);
        alta.setLocationRelativeTo(this);
        alta.setVisible(true);
    }//GEN-LAST:event_jBIngresarActionPerformed
 public void infonegocio(String nombre,String direccion,String tel,String rfc){
    jNombreEmpresa.setText(nombre);
    jDireccion.setText(direccion);
    jNumTel.setText(tel);
    jRfc.setText(rfc);
}

    public void setId(String id){
    jTID.setText(id);
    jTIDVenta.setText(id);
}
public void cerrar(){
Object [] opciones ={"Aceptar","Cancelar"};
int eleccion = JOptionPane.showOptionDialog(rootPane,"En realidad desea realizar cerrar la aplicacion","Mensaje de Confirmacion",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,null,opciones,"Aceptar");
if (eleccion == JOptionPane.YES_OPTION)
{
System.exit(0);
}else{
}
}
public void setC(){
        try {
           // int q=0;
            rs=con.Consulta("SELECT * FROM usuarios WHERE nivel = '1' OR nivel = '0'");
            while(rs.next()){
                jCuser.addItem(rs.getString(5));
            
            }
            
            
        } catch (SQLException ex) {
            Logger.getLogger(Interface.class.getName()).log(Level.SEVERE, null, ex);
        }

}
public void getT(String cad){
    aux3 = cad;
    System.out.println(aux3);
}

public void setT(String cad){
        String aux2 = cad;

}

public String getId(){
    cad = jTID.getText();
    return cad;
}

public String objectToString(Object o) {
        String st;
        st = (String) o;
        return st;
    }
public int getFactura(){
        return rowCount;
}

public int getNumFac(){
        return numfac;
}
 

 public void calcula () {        
    Calendar calendario1 = new GregorianCalendar();
    Date fechaHoraActual = new Date();


    calendario1.setTime(fechaHoraActual);
    ampm = calendario1.get(Calendar.AM_PM)==Calendar.AM?"AM":"PM";

    if(ampm.equals("PM")){
         int h = calendario1.get(Calendar.HOUR_OF_DAY);
         hora = h>9?""+h:"0"+h;
    }else{
         hora = calendario1.get(Calendar.HOUR_OF_DAY)>9?""+calendario1.get(Calendar.HOUR_OF_DAY):"0"+calendario1.get(Calendar.HOUR_OF_DAY);            
    }
    minutos = calendario1.get(Calendar.MINUTE)>9?""+calendario1.get(Calendar.MINUTE):"0"+calendario1.get(Calendar.MINUTE);
    segundos = calendario1.get(Calendar.SECOND)>9?""+calendario1.get(Calendar.SECOND):"0"+calendario1.get(Calendar.SECOND); 
}
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
        
            public void run() {
                
                new Interface().setVisible(true);
                
            }
        });
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JPanel Alertas;
    public javax.swing.JMenuItem Eliminar;
    public javax.swing.JPanel Productos;
    public javax.swing.JPanel Reportes;
    public javax.swing.JTable Talertas;
    public javax.swing.JTable Tlista;
    public javax.swing.JPanel Venta;
    public javax.swing.JButton jBIngresar;
    public javax.swing.JButton jBTotalVentas;
    public javax.swing.JButton jBVentaxDia;
    public javax.swing.JButton jBalertas;
    public javax.swing.JButton jBalertas1;
    public javax.swing.JButton jBbuscaxnombre;
    public javax.swing.JButton jBfactura;
    public javax.swing.JButton jBimprimir;
    public javax.swing.JButton jBmodificar;
    public javax.swing.JButton jBquitar;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JButton jButton5;
    public javax.swing.JCheckBox jCheckBox1;
    public javax.swing.JComboBox jCuser;
    public com.toedter.calendar.JDateChooser jDateChooser1;
    public com.toedter.calendar.JDateChooser jDateChooser2;
    public javax.swing.JLabel jDireccion;
    public javax.swing.JLabel jDireccion1;
    public javax.swing.JLabel jEtiRFC;
    public javax.swing.JLabel jEtiTel;
    public javax.swing.JLabel jLFechafinal;
    public javax.swing.JLabel jLFechainicial;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel12;
    public javax.swing.JLabel jLabel13;
    public javax.swing.JLabel jLabel16;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel22;
    public javax.swing.JLabel jLabel3;
    public javax.swing.JLabel jLabel32;
    public javax.swing.JLabel jLabel33;
    public javax.swing.JLabel jLabel34;
    public javax.swing.JLabel jLabel38;
    public javax.swing.JLabel jLabel41;
    public javax.swing.JLabel jLabel46;
    public javax.swing.JLabel jLabel7;
    public javax.swing.JLabel jLabel8;
    public javax.swing.JMenu jMenu1;
    public javax.swing.JMenu jMenu2;
    public javax.swing.JMenu jMenu4;
    public javax.swing.JMenu jMenu5;
    public javax.swing.JMenuBar jMenuBar1;
    public javax.swing.JMenuItem jMenuItem2;
    public javax.swing.JMenuItem jMenuItem3;
    public javax.swing.JMenuItem jMenuItem4;
    public javax.swing.JMenuItem jMenuItem5;
    public javax.swing.JMenuItem jMusers;
    public javax.swing.JLabel jNombreEmpresa;
    public javax.swing.JLabel jNumTel;
    public javax.swing.JLabel jNumVenta;
    public javax.swing.JPanel jPanel4;
    public javax.swing.JPopupMenu jPopupMenu1;
    public javax.swing.JLabel jRfc;
    public javax.swing.JScrollPane jScrollPane3;
    public javax.swing.JScrollPane jScrollPane5;
    public javax.swing.JScrollPane jScrollPane6;
    public javax.swing.JScrollPane jScrollPane9;
    public javax.swing.JTextField jTID;
    public javax.swing.JTextField jTIDVenta;
    public javax.swing.JTabbedPane jTabbedPane1;
    public javax.swing.JTextField jTbcodigobarras;
    public javax.swing.JTextField jTbdescripcion;
    public javax.swing.JTextField jTbnombre2;
    public javax.swing.JTable jTbuscar;
    public javax.swing.JTextField jTcodigodebarras;
    public javax.swing.JTextField jTinvT;
    public javax.swing.JTable jTinventario;
    public javax.swing.JTextField jTtotal;
    public javax.swing.JLabel lbHora;
    public javax.swing.JLabel lbHora1;
    public javax.swing.JLabel lbHora2;
    // End of variables declaration//GEN-END:variables

    public void run() {
        Thread ct = Thread.currentThread();
         while(ct == h1) {   
          this.calcula();
          lbHora.setText(hora + ":" + minutos + ":" + segundos + " "+ampm);
          lbHora1.setText(hora + ":" + minutos + ":" + segundos + " "+ampm);
          lbHora2.setText(hora + ":" + minutos + ":" + segundos + " "+ampm);
          try {
           Thread.sleep(1000);
          }catch(InterruptedException e) {}
         } 
        throw new UnsupportedOperationException("Not supported yet.");
        
    }

}


